﻿using FlexFlow.Model;
using FlexFlow.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FlexFlow.MVC.Controllers
{
    [Auth(AuthType.Page)]
    public class WorkFlowFormController : Controller
    {
        public ActionResult Edit(string formId,WorkFlowForm model = null,bool readOnly = false)
        {
            String path = Server.MapPath("~/WorkFlowForms/" + formId + ".cshtml");
            if (!System.IO.File.Exists(path))
            {
                return Content("模板不存在！");
            }

            RazorView view = new RazorView(this.ControllerContext, "~/WorkFlowForms/" + formId + ".cshtml", "", false, null);
            ViewResult res = View(view, model);
            res.ViewBag.ReadOnly = readOnly;
            return res;
        }
        public ActionResult Create()
        {
            return View();
        }
        public ActionResult Form(Guid formId)
        {
            OperateResult res = WorkFlowFormManager.Default.GetById(formId);
            if (res.ResultCode!=200)
            {
                return Content(res.Message + "[" + res.ResultCode + "]");
            }
            return View(res.Tag);
        }
    }
}
